<!--#include file="../nav/admin_top.php" --> 
<script type="text/javascript">
var url_save = '/admin_user/add?reqtype=json'; 
var url_return = '/admin_user/index';  
$().ready(function(){  
	showLoading();  
  $('#username').focus();
	
	
	
	o2js.build('dates'); 
	o2js.build('jscalendar');  
	/* 定时日期选择 */
	Calendar.setup({
		inputField:'bdate',
		button:'slt_bdate',
		ifFormat:"%Y-%m-%d",
	
		singleClick:true
	}); 
	/* 定时日期选择 */
	Calendar.setup({
		inputField:'edate',
		button:'slt_edate',
		ifFormat:"%Y-%m-%d",
	
		singleClick:true
	});
	Calendar.setup({
		inputField:'birthday',
		button:'slt_birthday',
		ifFormat:"%Y-%m-%d",
	
		singleClick:true
	});
	Calendar.setup({
		inputField:'contractdate',
		button:'slt_contractdate',
		ifFormat:"%Y-%m-%d",
	
		singleClick:true
	});
	
	
	
	
	o2js.build('o2citys');
	var slt1 = new o2Linkage({
		selects:[
			{
				id:'province',
				val:'广东省'
			},
			{
				id:'city',
				val:'深圳市'
			},
			{
				id:'area',
				val:'福田区'
			}
		]
	});
	
}); 



/* 配送类别改变 */
function fnDeliverChage(){
	if($('#sendtype').val() == '1'){
		$('#deliver_tr').show();
	}else{
		$('#deliver_tr').hide();
	}
}
			 


/* 保存 */
function fnSave(){ 
	var form = serializeObj("#myform");

	


	/* 一些验证 */
	if($.trim(form.username) == '' || !fnRegExp('reg_username',form.username) || form['username'].length<4){
		alert('请输入正确的【会员编号】，4-20位的英文或数字');
		$('#username').focus();
		return false;
	}
	if($.trim(form.password) == '' || form['password'].length<4){
		alert('请输入【登录密码】(请输入4-20位的登录密码)');
		$('#password').focus();
		return false;
	}
	
	if(form.sendtype == '1'){
		if(!form.deliver_id){
			alert('请选择有效的【配送方式】');
			$('#deliver_id').focus();
			return false;
		}
	}
	
	
	
	
	if(form.bdate == '' && form.edate == ''){
		alert('请填写【服务起止时间】'); 
		return false;
	}  
	//日期判断	 过期时间必须大于今天
	var ds = dateDiff('i',form.bdate,form.edate);
	if(ds <= 0 ){
		alert('【服务起止时间】的 开始时间 必须小于 结束时间'); 
		return false;
	} 
	
	
	
	
	
	
	
	if($.trim(form.name) == ''){
		alert('请输入正确的【会员姓名】');
		$('#name').focus();
		return false;
	}
	if($('#phone').val()!='' && !fnRegExp('reg_mobile',$('#phone').val())){
		alert('请输入正确的【手机号码】');
		$('#phone').focus();
		return false;
	}
	if($('#email').val()!='' && !fnRegExp('reg_email',$('#email').val())){
		alert('请输入正确的【Email】');
		$('#email').focus();
		return false;
	}
  
  $('button').attr('disabled','disabled');
	$.ajax({
		async:true,
		type:'post',
		url:url_save,
		data:{
			form:JSON.encode(form) 
		},
		success:function(e){
  		$('button').attr('disabled','');
			var ok = errorHandler(e);
			if(ok){　 
				jumpTo(url_return);
			}
		}
	});
}
</script>
<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">会员列表 - 添加会员</span>
		<span class="totalSpan"> <label id="captionNum"></label> </span>
	</div>
</div> 
 
<form id="myform" action="" method="post" onsubmit="return false" >
<div class="blockdiv">
	<div class="titlediv">账户信息</div>
	<table class="mytable" > 
		<tr>
			<td class="mylabel"><span class="red">*</span>会员编号：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="username" name="username" maxlength="20" style="width:200px" />
				<span class="gray">请输入4-20位英文字母或数字</span>
			</td>  
		</tr> 
		<tr>
			<td class="mylabel"><span class="red">*</span>登录密码：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="password" name="password" maxlength="20" style="width:200px" />
				<span class="gray">请输入4-20位的登录密码</span>
			</td>  
		</tr>  
		<tr>
			<td class="mylabel"><span class="red">*</span>账户状态：</td>
			<td class="myinfo" >
				<select class="textBox" id="state" name="state">
					<option value="0" >意向客户</option>
					<option value="1" selected="selected">会员</option>
					<option value="2" >暂停</option>
					<option value="3" >取消</option>
				</select>
			</td>  
		</tr>
		<tr>
			<td class="mylabel"><span class="red">*</span>配送类别：</td>
			<td class="myinfo" >
				<select class="textBox" id="sendtype" name="sendtype" onchange="fnDeliverChage()">
					<option value="0" selected="selected">乐园卡</option>
					<option value="1" >田园卡</option>
				</select>
				<span class="gray">乐园卡：由配送管理员设置配送。田园卡：由会员自行登录购买菜品下单，再进行配送</span>
			</td>  
		</tr>
		<tr id="deliver_tr" style="display:none">
			<td class="mylabel"><span class="red">*</span>配送方式：</td>
			<td class="myinfo" >
				<select class="textBox" id="deliver_id" name="deliver_id">
					<?PHP 
					foreach($rs_deliver as $v ){
						echo '<option value="'.$v['id'].'" >'.$v['name'].'</option>';
					}
					?>
				</select>
				<span class="gray">配送方式决定选菜订单的运费规则，详情请查询对应的【系统 - 配送方式】维护</span>
			</td>  
		</tr>
		<tr>
			<td class="mylabel"><span class="red">*</span>服务起止时间：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="bdate" name="bdate"  value="" style="width:140px"   readonly="readonly" />
				<input type="button" class="btnicon_calendar" id="slt_bdate" />
				至
				<input type="text" class="textBox" id="edate" name="edate"  value="" style="width:140px"  readonly="readonly"  />
				<input type="button" class="btnicon_calendar" id="slt_edate" />
				
			</td>  
		</tr>
	</table> 
</div> 
	
 
<div class="blockdiv">
	<div class="titlediv">会员基本信息</div>
	<table class="mytable" >
		<tr>
			<td class="mylabel"><span class="red">*</span>会员姓名：</td>
			<td class="myinfo" colspan="3" >
				<input type="text" class="textBox" id="name" name="name" maxlength="10" /> 
			</td>  
		</tr> 
		<tr> 
			<td class="mylabel">会员类型：</td>
			<td class="myinfo" >
				<?PHP
				echo factory::module('list')->gethtml('user_classes','','class="textBox" id="classes" name="classes"');
				?>
				
			</td> 
			<td class="mylabel">性别：</td>
			<td class="myinfo" >
				<select class="textBox" id="sex" name="sex" >
					<option value="男" selected="selected">男</option>
					<option value="女">女</option>
				</select>
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">证件类型：</td>
			<td class="myinfo" >
				<?PHP
				echo factory::module('list')->gethtml('identname','','class="textBox" id="identname" name="identname"');
				?>
			</td>  
			<td class="mylabel">证件号码：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="identnumber" name="identnumber" maxlength="50" /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">籍贯：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="hometown" name="hometown"  maxlength="50" /> 
			</td>  
			<td class="mylabel">出生年月：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="birthday" name="birthday" maxlength="50" readonly="readonly" /> 
				<input type="button" class="btnicon_calendar" id="slt_birthday" />
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">客户来源：</td>
			<td class="myinfo" >
				<?PHP
				echo factory::module('list')->gethtml('source','','class="textBox" id="source" name="source"');
				?>
			</td>  
			<td class="mylabel">业务代表：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="busiman" name="busiman" maxlength="50"  /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">饮食偏好：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="foodlike" name="foodlike" maxlength="255"   /> 
			</td> 
			<td class="mylabel">家庭人数：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="person" name="person" maxlength="50"  /> 
			</td>  
		</tr>
		<tr>
			<td class="mylabel">手机号码：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="phone" name="phone" maxlength="50"   /> 
			</td>   
			<td class="mylabel">Email：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="email" name="email" maxlength="255" style="width:200px" /> 
			</td>  
		</tr>
		 
		<tr>
			<td class="mylabel">固定电话：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="tel" name="tel" maxlength="50"  /> 
			</td>  
			<td class="mylabel">联系地址：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="addr" name="addr" maxlength="255"  style="width:200px"   /> 
			</td> 
		</tr>
		 
		<tr>
			<td class="mylabel">备注：</td>
			<td class="myinfo" colspan="3" >
				<textarea class="textBox" style="height:50px;width:80%" id="remark" name="remark" ></textarea>
			</td>  
		</tr>
	</table>
</div>
<div class="blockdiv">
	<div class="titlediv">配送信息</div>
	<table class="mytable" >
		<tr>
			<td class="mylabel">配送地区：</td>
			<td class="myinfo" colspan="1" >
				<select id="province" name="province" class="textBox"></select> - 
				<select id="city" name="city" class="textBox"></select> - 
				<select id="area" name="area" class="textBox"></select>
				 
			</td> 
			<td class="mylabel">小区名称：</td>
			<td class="myinfo" colspan="1" >
				<?PHP
				echo factory::module('list')->gethtml('zone','','class="textBox" id="zone" name="zone"');
				?>
			</td> 
		</tr>	
		<tr>
			<td class="mylabel">配送频次1：</td>
			<td class="myinfo" >
				<select class="textBox" id="sendweek1" name="sendweek1" >
					<option value="星期一" selected="selected">星期一</option>
					<option value="星期二">星期二</option>
					<option value="星期三">星期三</option>
					<option value="星期四">星期四</option>
					<option value="星期五">星期五</option>
					<option value="星期六">星期六</option>
					<option value="星期日">星期日</option>
				</select>
			</td> 
			<td class="mylabel">配送频次2：</td>
			<td class="myinfo" >
				<select class="textBox" id="sendweek2" name="sendweek2" >
					<option value="星期一" >星期一</option>
					<option value="星期二">星期二</option>
					<option value="星期三">星期三</option>
					<option value="星期四" selected="selected">星期四</option>
					<option value="星期五">星期五</option>
					<option value="星期六">星期六</option>
					<option value="星期日">星期日</option>
				</select>
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">配送联系人：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="sendman" name="sendman" maxlength="10" style="width:200px" /> 
			</td> 
			<td class="mylabel">配送联系电话：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="sendphone" name="sendphone" maxlength="50" style="width:200px" /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">配送地址：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="sendaddr" name="sendaddr" maxlength="255" style="width:200px" /> 
			</td>  
			<td class="mylabel">配送时间段：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="sendtime" name="sendtime" maxlength="255" style="width:200px" /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">备用配送联系人：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="bsendman" name="bsendman" maxlength="10" style="width:200px" /> 
			</td> 
			<td class="mylabel">备用配送联系电话：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="bsendphone" name="bsendphone" maxlength="50" style="width:200px" /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">备用配送地址：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="bsendaddr" name="bsendaddr" maxlength="255" style="width:200px" /> 
			</td>  
			<td class="mylabel">备用配送时间段：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="bsendtime" name="bsendtime" maxlength="255" style="width:200px" /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">配送特殊需求：</td>
			<td class="myinfo" colspan="3" >
				<textarea class="textBox" style="height:50px;width:80%" id="sendremark" name="sendremark" ></textarea>
			</td>  
		</tr>
	</table>
</div>		
<div class="blockdiv">
	<div class="titlediv">合同信息</div>
	<table class="mytable" > 
		<tr>
			<td class="mylabel">合同编号：</td>
			<td class="myinfo" colspan="3" >
				<input type="text" class="textBox" id="contractcode" name="contractcode" maxlength="255" style="width:200px" /> 
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">合同金额：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="contractmoney" name="contractmoney" maxlength="10"   /> 
			</td> 
			<td class="mylabel">合同日期：</td>
			<td class="myinfo" >
				<input type="text" class="textBox" id="contractdate" name="contractdate" maxlength="20" readonly="readonly" /> 
				<input type="button" class="btnicon_calendar" id="slt_contractdate" />
			</td>  
		</tr> 
		<tr>
			<td class="mylabel">合同备注：</td>
			<td class="myinfo" colspan="3" >
				<textarea class="textBox" style="height:50px;width:80%" id="contractremark" name="contractremark" ></textarea>
			</td>  
		</tr>
	</table>
</div>		
</form>			
<div  class="button_div">
		<button class="btn_save" onclick="fnSave()">保 存</button>
		<span class="gray">或</span> 
		<button class=" " onclick="jumpTo(url_return)">返 回</button>
</div>  
<!--#include file="../nav/admin_bottom.php" -->